package com.dllo.lanou.cookapp.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.dllo.lanou.cookapp.R;
import com.dllo.lanou.cookapp.adapter.HomeViewpageAdapter;

/**
 * Created by xijinhua on 2016/3/10.
 */
public class BaseFragment extends Fragment {
    private TabLayout tabLayout;
    private ViewPager homeviewPager;
    private HomeViewpageAdapter adapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_base, null);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        //控件初始化
        init(view);
        tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
        tabLayout.setSelectedTabIndicatorColor(getResources().getColor(android.R.color.holo_green_dark));
        tabLayout.setTabTextColors(getResources().getColor(android.R.color.black),
                getResources().getColor(android.R.color.holo_green_dark));
       // tabLayout.setSelectedTabIndicatorColor();
       // tabLayout.setBackgroundColor(getResources().getColor(android.R.color.holo_green_dark));


    }

    private void init(View view) {
        tabLayout = (TabLayout) view.findViewById(R.id.tabLayout);
        homeviewPager = (ViewPager) view.findViewById(R.id.viewPager);
        adapter = new HomeViewpageAdapter(getChildFragmentManager());
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        //添加数据
        homeviewPager.setAdapter(adapter);
        //将viewpager和tablayout绑定
        tabLayout.setupWithViewPager(homeviewPager);

    }

}
